﻿Public Class frmLoginAeroGlass

    Private Sub frmLoginAeroGlass_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'FORMATEAR ELEMENTOS
        txtPass.BackColor = System.Drawing.Color.FromArgb(216, 221, 224)
        txtUser.BackColor = System.Drawing.Color.FromArgb(216, 221, 224)
        txtMail.BackColor = System.Drawing.Color.FromArgb(216, 221, 224)
        txtMail.Border.BorderColor = System.Drawing.Color.FromArgb(216, 221, 224)
        txtMail.Border.BorderColor2 = System.Drawing.Color.FromArgb(216, 221, 224)
        txtPass.Border.BorderColor = System.Drawing.Color.FromArgb(216, 221, 224)
        txtPass.Border.BorderColor2 = System.Drawing.Color.FromArgb(216, 221, 224)
        txtUser.Border.BorderColor = System.Drawing.Color.FromArgb(216, 221, 224)
        txtUser.Border.BorderColor2 = System.Drawing.Color.FromArgb(216, 221, 224)
        txtPass.ForeColor = System.Drawing.Color.FromKnownColor(KnownColor.GrayText)
        txtUser.ForeColor = System.Drawing.Color.FromKnownColor(KnownColor.GrayText)
        txtMail.ForeColor = System.Drawing.Color.FromKnownColor(KnownColor.GrayText)

        panelMail.BackColor = System.Drawing.Color.FromArgb(216, 221, 224)
        panelUser.BackColor = System.Drawing.Color.FromArgb(216, 221, 224)
        panelPass.BackColor = System.Drawing.Color.FromArgb(216, 221, 224)

        btnConecta.BackColor = System.Drawing.Color.FromArgb(72, 90, 104)
        btnMail.BackColor = System.Drawing.Color.FromArgb(72, 90, 104)
        btnReintentar.BackColor = System.Drawing.Color.FromArgb(72, 90, 104)
        btnConecta.FlatAppearance.BorderColor = System.Drawing.Color.FromArgb(72, 90, 104)
        btnMail.FlatAppearance.BorderColor = System.Drawing.Color.FromArgb(72, 90, 104)
        btnReintentar.FlatAppearance.BorderColor = System.Drawing.Color.FromArgb(72, 90, 104)
        btnConecta.ForeColor = System.Drawing.Color.FromArgb(224, 224, 224)
        btnMail.ForeColor = System.Drawing.Color.FromArgb(224, 224, 224)
        btnReintentar.ForeColor = System.Drawing.Color.FromArgb(224, 224, 224)

        btnOlvido.BackColor = Color.White
        btnOlvido.FlatAppearance.BorderColor = Color.White
        btnOlvido.ForeColor = Color.Gray

        btnDactilar.BackColor = Color.White
        btnDactilar.FlatAppearance.BorderColor = Color.White
        btnDactilar.ForeColor = Color.Gray

        lblDedo.BackColor = Color.White
        lblMail.BackColor = Color.White
        lblDescCorreo.BackColor = Color.White
        lblDedo.ForeColor = Color.Gray
        lblMail.ForeColor = Color.Gray
        lblDescCorreo.ForeColor = Color.Gray
        lblCitra.BackColor = Color.White
        lblCitra.ForeColor = Color.Silver

        PageSlider1.SelectedPage = PageSliderPage1

    End Sub

    Sub Ingresar()
        If Len(txtUser.Text) > 0 Then
            Dim IdUsuario As Integer = 0
            IdUsuario = BuscarIntDatoInicial("SELECT IDUSUARIO FROM USUARIOS_CITRA WHERE UPPER(NOMBRE_USUARIO)='" & UCase(txtUser.Text) & "'")
            If IdUsuario > 0 Then
                Dim Estatus As Integer = BuscarIntDatoInicial("SELECT ESTATUS FROM USUARIOS_CITRA WHERE IDUSUARIO=" & IdUsuario)
                If Estatus = 1 Then
                    Dim Password As String = BuscarStrDatoInicial("SELECT PASS FROM USUARIOS_CITRA WHERE IDUSUARIO=" & IdUsuario)
                    If txtPass.Text = Password Then
                        NIVEL_USUARIO = BuscarIntDatoInicial("SELECT IDNIVEL FROM USUARIOS_CITRA WHERE IDUSUARIO=" & IdUsuario)
                        Conectar()


                    Else
                        MsgBox("La contraseña es incorrecta", MsgBoxStyle.Information, "Aviso")
                        txtPass.Clear()
                        txtPass.Focus()
                    End If
                Else
                    MsgBox("El usuario esta inactivo", MsgBoxStyle.Information, "Aviso")
                    txtUser.Clear()
                    txtUser.Focus()
                End If

            Else
                MsgBox("El nombre de usuario indicado no existe", MsgBoxStyle.Information, "Aviso")
                txtUser.SelectAll()
                txtUser.Focus()
            End If

        Else
            MsgBox("Debes indicar tu nombre de usuario", MsgBoxStyle.Information, "Aviso")
            txtUser.Focus()

        End If
    End Sub

    Private Sub btnConectar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Ingresar()
    End Sub
    Sub Conectar()


        UsuarioActivo = UCase(txtUser.Text)
        ' Bitacora("Ingreso al sistema")
        ClienteCitra.EnviarDatos("+" & UsuarioActivo)
        Me.DialogResult = Windows.Forms.DialogResult.OK
        Close()
    End Sub

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        'Me.DialogResult = Windows.Forms.DialogResult.Cancel
        'Close()
        PageSliderPage3.Visible = False
        PageSliderPage2.Visible = True
        PageSlider1.SelectedPage = PageSliderPage1

    End Sub

    
    Private Sub btnRegresaMail_Click(sender As System.Object, e As System.EventArgs) Handles btnRegresaMail.Click
        PageSliderPage2.Visible = False
        PageSliderPage1.Visible = True
        PageSlider1.SelectedPage = PageSliderPage1

    End Sub

    Private Sub btnOlvido_Click(sender As System.Object, e As System.EventArgs) Handles btnOlvido.Click
        PageSliderPage2.Visible = False
        PageSliderPage3.Visible = True
        PageSlider1.SelectedPage = PageSliderPage3
    End Sub

    Private Sub btnDactilar_Click(sender As System.Object, e As System.EventArgs) Handles btnDactilar.Click
        PageSliderPage2.Visible = True
        PageSlider1.SelectedPage = PageSliderPage2
    End Sub

    Private Sub btnAceptar_Click(sender As System.Object, e As System.EventArgs)

    End Sub

    Private Sub btnConecta_Click(sender As System.Object, e As System.EventArgs) Handles btnConecta.Click
        Ingresar()


    End Sub

    Private Sub txtUser_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles txtUser.KeyDown
        If e.KeyCode = Keys.Enter Then
            Dim IdUsuario As Integer = 0
            IdUsuario = BuscarIntDatoInicial("SELECT IDUSUARIO FROM USUARIOS_CITRA WHERE UPPER(NOMBRE_USUARIO)='" & UCase(txtUser.Text) & "'")
            If IdUsuario > 0 Then
                txtPass.Focus()
            Else
                txtUser.Clear()
                txtUser.Focus()
            End If
        ElseIf e.KeyCode = Keys.Tab Then
            Dim IdUsuario As Integer = 0
            IdUsuario = BuscarIntDatoInicial("SELECT IDUSUARIO FROM USUARIOS_CITRA WHERE UPPER(NOMBRE_USUARIO)='" & UCase(txtUser.Text) & "'")
            If IdUsuario > 0 Then
                txtPass.Focus()
            Else
                txtUser.Clear()
                txtUser.Focus()
            End If
        ElseIf e.KeyCode = Keys.Escape Then
            Me.DialogResult = Windows.Forms.DialogResult.Cancel
            Close()

        End If

    End Sub

    Private Sub txtUser_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtUser.TextChanged

    End Sub


    Private Sub txtPass_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtPass.KeyDown
        If e.KeyCode = Keys.Enter Then
            Ingresar()
        ElseIf e.KeyCode = Keys.Tab Then
            Ingresar()
        ElseIf e.KeyCode = Keys.Escape Then
            Me.DialogResult = Windows.Forms.DialogResult.Cancel
            Close()

        End If
    End Sub

    Private Sub txtPass_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtPass.TextChanged

    End Sub
End Class